<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>ajax跨域传参 图片加载确定大小</title>
    <script src="<?php echo PUBLIC_PATH;?>/js/jquery.js"></script>

</head>

<body>
<script>
    function resizeImage(obj, MaxW, MaxH)
    {
        var imageObject = obj;
        var state = imageObject.readyState;
//        if(state!='complete')
//        {
//            setTimeout("resizeImage("+imageObject+","+MaxW+","+MaxH+")",50);
//            return;
//        }

        var oldImage = new Image();
        oldImage.src = imageObject.src;
        var dW = oldImage.width;
        var dH = oldImage.height;
        if(dW>MaxW || dH>MaxH)
        {
            a = dW/MaxW; b = dH/MaxH;
            if( b>a ) a = b;
            dW = dW/a; dH = dH/a;
        }
        if(dW > 0 && dH > 0)
        {
            imageObject.width = dW;
            imageObject.height = dH;
        }
    }
</script>
<hr />

<?php echo $a; ?>
<?php echo $bbb; ?>
<hr />
<img src="<?php echo PUBLIC_PATH;?>/image/1.png" onload="resizeImage(this,100,100)"><br />
<img src="<?php echo PUBLIC_PATH;?>/image/2.png" onload="resizeImage(this,200,200)"><br />
<img src="<?php echo PUBLIC_PATH;?>/image/2.png" onload="resizeImage(this,400,400)"><br />
<form name="form">
    <input type="text" name="sex">
    <input type="text" name="age">
    <input type="button" id="btn" value="button" />
</form>
<script>

    $(document).ready(function(){
        var url="/index.php?c=ajax&a=roback";
        $("#btn").click(function(k) {
            var j = $("form").serializeArray();//序列化name/value
            $.ajax({
                type: 'GET',  //这里用GET
                url:'http://zdw.tunnel.2bdata.com',
                dataType: 'jsonp',  //类型
                data: j,
                jsonp: 'callback', //jsonp回调参数，必需
                async: false,
                success: function(result) {//返回的json数据
                    alert(result.msg); //回调输出
                    result = result || {};
                    if (result.msg=='err'){
                        alert(result.info);
                    }else if (result.msg=="ok"){
                        alert('提交成功');
                    }else{
                        alert('提交失败');
                    }
                },
                timeout: 3000
            })
        });
    });
</script>
</body>
</html>